﻿using System;
using System.Windows.Forms;
using Company.BLL;
using Company.BLL.KDT.SXXK;
using Company.BLL.DuLieuChuan;
using Janus.Windows.GridEX;

namespace Company.Interface.KDT.GC
{
    public partial class ToKhaiGCCTRegistedForm : BaseForm
    {
        //private DinhMucDangKy dmDangKy = new DinhMucDangKy();

        //-----------------------------------------------------------------------------------------
        public ToKhaiGCCTRegistedForm()
        {
            InitializeComponent();
        }

        //-----------------------------------------------------------------------------------------
        /// <summary>
        /// Khởi tạo dữ liệu chuẩn.
        /// </summary>
        private void khoitao_DuLieuChuan()
        {
            this._DonViHaiQuan = DonViHaiQuan.SelectAll();
            this._DonViTinh = DonViTinh.SelectAll();
        }

        //-----------------------------------------------------------------------------------------
        private void PhuKienGCManageForm_Load(object sender, EventArgs e)
        {
            this.khoitao_DuLieuChuan();
            //dgList.DataSource = this.dmDangKy.DMCollection;
        }

        //-----------------------------------------------------------------------------------------
        /// <summary>
        /// Gửi thông tin đăng ký đến Hải quan.
        /// </summary>
        private void send()
        {            
            //try
            //{
            //    this.Cursor = Cursors.WaitCursor;
            //    if (this.dmDangKy.DMCollection.Count > 0)
            //    {
            //        // Master.
            //        this.dmDangKy.MaHaiQuan = ctrDonViHaiQuan.Ma;
            //        this.dmDangKy.MaDoanhNghiep = GlobalSettings.MA_DON_VI;
            //        this.dmDangKy.MaDaiLy = GlobalSettings.MA_DAI_LY;
            //        string returnMessage = string.Empty;
            //        this.dmDangKy.WSSend();
            //        txtSoTiepNhan.Text = this.dmDangKy.SoTiepNhan.ToString();
            //        lblTrangThai.Text = "Chờ duyệt chính thức";
            //        cmdSend.Enabled = Janus.Windows.UI.InheritableBoolean.False;
            //        cmdSave.Enabled = Janus.Windows.UI.InheritableBoolean.False;
            //        cmdAdd.Enabled = Janus.Windows.UI.InheritableBoolean.False;
            //        ShowMessage("Đăng ký thành công!\nSố tiếp nhận đăng ký điện tử: " + this.dmDangKy.SoTiepNhan.ToString(), false);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //finally
            //{
            //    this.Cursor = Cursors.Default;
            //}
        }

        //-----------------------------------------------------------------------------------------
        /// <summary>
        /// Thêm mới định mức.
        /// </summary>
        private void add()
        {
            //DinhMucEditForm f = new DinhMucEditForm();
            //f.OpenType = OpenFormType.Insert;
            //f.MaDoanhNghiep = GlobalSettings.MA_DON_VI;
            //f.MaHaiQuan = ctrDonViHaiQuan.Ma;
            //f.ShowDialog();

            //if (f.DMDetail != null)
            //{
            //    this.dmDangKy.DMCollection.Add(f.DMDetail);
            //    dgList.Refetch();
            //}
        }

        //-----------------------------------------------------------------------------------------
        private void ctrDonViHaiQuan_ValueChanged(object sender, EventArgs e)
        {

        }

        //-----------------------------------------------------------------------------------------
        private void dgList_LoadingRow(object sender, RowLoadEventArgs e)
        {
            if (e.Row.RowType == RowType.Record)
            {
                //e.Row.Cells["DVT_ID"].Text = this.DonViTinh_GetName(e.Row.Cells["DVT_ID"].Value.ToString());
            }
        }

        //-----------------------------------------------------------------------------------------
        private void dgList_RowDoubleClick(object sender, RowActionEventArgs e)
        {
            //GridEXSelectedItemCollection items = dgList.SelectedItems;
            //foreach (GridEXSelectedItem i in items)
            //{
            //    if (i.RowType == RowType.Record)
            //    {
            //        DinhMucEditForm f = new DinhMucEditForm();
            //        f.OpenType = OpenFormType.Edit;
            //        f.DMDetail = this.dmDangKy.DMCollection[i.Position];
                    
            //        f.ShowDialog();
            //        if (f.DMDetail != null)
            //        {
            //            this.dmDangKy.DMCollection[i.Position] = f.DMDetail;
            //        }
            //        dgList.Refetch();
            //    }
            //    break;
            //}
        }

        //-----------------------------------------------------------------------------------------
        /// <summary>
        /// Lưu thông tin.
        /// </summary>
        private void save()
        {
            //try
            //{
            //    this.Cursor = Cursors.WaitCursor;
            //    if (this.dmDangKy.DMCollection.Count > 0)
            //    {
            //        // Master.
            //        this.dmDangKy.MaHaiQuan = ctrDonViHaiQuan.Ma;
            //        if (this.dmDangKy.ID == 0)
            //        {
            //            this.dmDangKy.MaDaiLy = GlobalSettings.MA_DAI_LY;
            //            this.dmDangKy.MaDoanhNghiep = GlobalSettings.MA_DON_VI;                        
            //            this.dmDangKy.TrangThaiXuLy = TrangThaiXuLy.CHUA_KHAI_BAO;
            //            //this.dmDangKy.SoTiepNhan = 0;
            //            //this.dmDangKy.NgayTiepNhan = DateTime.Today;
                        
            //        }                    
            //        // Detail.
            //        int sttHang = 1;
            //        foreach (DinhMuc nplD in this.dmDangKy.DMCollection)
            //        {
            //            nplD.STTHang = sttHang++;
            //        }

            //        if (this.dmDangKy.InsertUpdateFull()) 
            //            ShowMessage("Cập nhật thành công", false);
            //        else
            //            ShowMessage("Cập nhật không thành công", false);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("Có lỗi:" + ex.Message);
            //}
            //finally
            //{
            //    this.Cursor = Cursors.Default;
            //}        
        }

        //-----------------------------------------------------------------------------------------
        private void cmMain_CommandClick(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e)
        {
            switch (e.Command.Key)
            {
                case "cmdSave":
                    this.save();
                    break;
                case "cmdAdd":
                    this.add();
                    break;
                case "cmdSend":
                    this.send();
                    break;
            }
        }
    }
}